package it.polimi.it.TravelDream.entities;

import it.polimi.it.TravelDream.ejb.eaos.PackageDTO;
import it.polimi.it.TravelDream.ejb.eaos.PersonalizePackageDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.util.Date;
import java.util.Date;
import java.util.Random;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;



/**
 * The persistent class for the personalized_package database table.
 * 
 */
@Entity
@Table(name="personalized_package")
@NamedQuery(name="PersonalizedPackage.findAll", query="SELECT p FROM PersonalizedPackage p")
public class PersonalizedPackage implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private String idpackage;

	@Temporal(TemporalType.DATE)
	private Date creationdata;

	private String idbasicproduct1;

	private String idbasicproduct2;

	private String idbasicproduct3;

	private int totalprice;

	private String usercreator;

static final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
    static Random rnd = new Random(System.currentTimeMillis());
    
    static private final int LENGHT = 4;
    
	
	 public PersonalizedPackage(){};
	
	
	
	 
	public PersonalizedPackage(PackageDTO pack, String userCreator) {
		//Date date = new Date();
		//DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
		//this.creationdata =  dateFormat.format(date);
		this.idbasicproduct1 = pack.getIdBasicProduct1();
		this.idbasicproduct2 = pack.getIdBasicProduct2();
		this.idbasicproduct3 = pack.getIdBasicProduct3();
		this.idpackage = generateIDPackage(userCreator);
		this.totalprice = pack.getTotalPrice();
		this.usercreator = userCreator;
	
		
		
	}
	
	public PersonalizedPackage(PersonalizePackageDTO pack, String userCreator) {
		//Date date = new Date();
		//DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
		//this.creationdata =  dateFormat.format(date);
		this.idbasicproduct1 = pack.getIdbasicproduct1();
		this.idbasicproduct2 = pack.getIdbasicproduct2();
		this.idbasicproduct3 = pack.getIdbasicproduct3();
		this.idpackage = pack.getIdpackage();
		this.totalprice = pack.getTotalprice();
		this.usercreator = userCreator;	
	}
	
	
	private String generateIDPackage(String userCreator){
		StringBuilder sb = new StringBuilder(LENGHT);
        for (int i = 0; i < LENGHT; i++) {
            sb.append(ALPHABET.charAt(rnd.nextInt(ALPHABET.length())));
        }
        return sb.toString() + userCreator;
	}
	

	public String getIdpackage() {
		return this.idpackage;
	}

	public void setIdpackage(String idpackage) {
		this.idpackage = idpackage;
	}

	public Date getCreationdata() {
		return this.creationdata;
	}

	public void setCreationdata(Date creationdata) {
		this.creationdata = creationdata;
	}

	public String getIdbasicproduct1() {
		return this.idbasicproduct1;
	}

	public void setIdbasicproduct1(String idbasicproduct1) {
		this.idbasicproduct1 = idbasicproduct1;
	}

	public String getIdbasicproduct2() {
		return this.idbasicproduct2;
	}

	public void setIdbasicproduct2(String idbasicproduct2) {
		this.idbasicproduct2 = idbasicproduct2;
	}

	public String getIdbasicproduct3() {
		return this.idbasicproduct3;
	}

	public void setIdbasicproduct3(String idbasicproduct3) {
		this.idbasicproduct3 = idbasicproduct3;
	}

	public int getTotalprice() {
		return this.totalprice;
	}

	public void setTotalprice(int totalprice) {
		this.totalprice = totalprice;
	}

	public String getUsercreator() {
		return this.usercreator;
	}

	public void setUsercreator(String usercreator) {
		this.usercreator = usercreator;
	}

}